package me.sdevil507.biz.fruit.repository;

import me.sdevil507.biz.fruit.po.FruitAuthorPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: tips_back_end
 * @description: 成果作者对象
 * @author: kzl
 * @create: 2020-06-23 17:30
 **/
public interface FruitAuthorRepository extends JpaRepository<FruitAuthorPO, Long>, JpaSpecificationExecutor<FruitAuthorPO>, QuerydslPredicateExecutor<FruitAuthorPO> {

    /**
     * @ClassName FruitAuthorRepository
            * @Description : 功能说明
            *
     * @param tempId
     * @param userId
            * @Return : void
            * @Author : kzl
            * @Date : 2020/8/18 11:02
    */
    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update FruitAuthorPO a set a.orgUserId=:userId,a.isTemp=false where a.orgUserId=:tempId")
    void temporaryBecomeFormal(@Param("tempId") Long tempId,@Param("userId") Long userId);

    /**
     * @ClassName FruitAuthorRepository
            * @Description : 功能说明
            *
     * @param tempId
     * @param userId
            * @Return : void
            * @Author : kzl
            * @Date : 2020/8/18 11:02
    */
    @Transactional(rollbackFor = Exception.class)
    @Modifying(clearAutomatically = true)
    @Query(value = "update FruitAuthorPO a set a.orgUserId=:userId where a.orgUserId=:tempId")
    void updateAuthorId(@Param("tempId") Long tempId,@Param("userId") Long userId);

}
